﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Product_Detail : System.Web.UI.Page
{
    Cart gh;
    SanPham sp = new SanPham();
    AccessData ac = new AccessData();
    int masp;
    string ten;
    string email;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            masp = int.Parse(Request.QueryString.Get("masp"));
            lblMaSP.Text = masp.ToString();
            sp.CT(masp);
            lblTenSP.Text = sp.Ten_SP.ToString();
            lblGia.Text = sp.Gia.ToString() + " đ";
            if (sp.So_luong > 0)
                lblSoLuong.Text = "Còn " + sp.So_luong.ToString() + " sản phẩm";
            else lblSoLuong.Text = "Đã hết hàng";
            imgSP.ImageUrl = sp.Hinh.ToString();
            linkcrumTEN.Text = sp.Ten_SP.ToString();
            Label1.Text = sp.Mo_ta.ToString();

            ten = Request.Cookies["LoginUser"]["HoTen"].ToString();
            email = Request.Cookies["LoginUser"]["Email"].ToString();
        }
        catch
        {
            
           
        }
      
   

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        ac.ExeCuteNonquery("insert into BinhLuan(tennguoinhan,email,noidung,masp) values(N'" + ten + "','" + email + "',N'" + txtND.Text + "','" + masp + "')");
        Response.Redirect(string.Format("Product-Detail.aspx?masp={0}", masp));
    }
    protected void btnThemVaoGioHang_Click(object sender, EventArgs e)
    {
        gh = new Cart();
        DataTable tb;
        if (Session["GioHang"] == null)
            tb = gh.setTable();
        else
            tb = (DataTable)Session["GioHang"];
        DataTable dt = gh.giohang(int.Parse(lblMaSP.Text));
        foreach (DataRow dr in dt.Rows)
        {
            tb = gh.dienVaoBang(tb, dr["Hinhanh"].ToString(), dr["TenSP"].ToString(), 1, double.Parse(dr["Gia"].ToString()), dr["MaSP"].ToString());
            Session["GioHang"] = tb;
        }
        Response.Redirect("GioHang.aspx");

    }
    protected void btnMua_Click(object sender, EventArgs e)
    {

    }
}